package cn.t222.ch03.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.sql.SQLOutput;
import java.text.SimpleDateFormat;
import java.util.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Book extends Object implements Cloneable {
    private Integer id;
    private String name;
    private String author;
    private Date date;
    private Address address;
    @Override
    public Object clone() throws CloneNotSupportedException {
        Book book = (Book) super.clone();
        Address address = (Address) book.getAddress().clone();
        book.setAddress(address);
        return book;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        Book book = (Book) obj;
        return book.getId().equals(this.id);
    }
    public static void main(String[] args) throws Exception{
        Book book1 = new Book(2,"西游记","吴承恩",new Date(), new Address("湖南","岳阳"));
//        Book book2 = new Book(2,"西游记2","吴承恩2",new Date());
        Book book3 = (Book) book1.clone();
        book3.setName("aaa");
        book3.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2019-01-01"));
        book3.getAddress().setType("湖北");
        book3.getAddress().setValue("武汉");
        System.out.println(book1);
        System.out.println(book3);
        new ArrayList<>();
        new Vector<>(10,5).add(1);
        Hashtable h;
        HashMap m;
        LinkedList a; a.add()
    }



}
@Data
@AllArgsConstructor
@ToString
 class Address implements Cloneable{
    private String type;
    private String value;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
